

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<script type="text/javascript" src="helpman_topicinit.js"></script>

<title>Set Up Unit Testing [Enterprise Architect User Guide]</title>

<meta name="keywords" content="Enterprise Architect, Sparx Systems, UML, Unit Testing,Unit Testing Set Up,Unit Testing Define Tests,Unit Testing Create Build and Test Scripts">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />

<link type="text/css" href="default.css" rel="stylesheet" />
<style type="text/css">
  A, A:Visited
  {
    color: #00F;
  }

  A:Active, A:Hover
  {
    color: #F00;
  }

  OL
  {
    margin: 5px 0 5px 48px;
  }

  UL
  {
    margin-bottom: 3px;
    margin-top: 0;
  }

  #nsr
  {
    background-color: #D4DFFF;
  }

  #nsr A
  {
    text-decoration: none;
  }

  #mainbody
  {
    padding: 8px;
  }

  .p_BodyText
  {
    padding: 5px 0;
  }
</style>



<style type="text/css" media="screen">
  BODY
  {
    background-color: #FFFFFF;
  }

  #nsr
  {
    padding: 6px 6px 0 6px;
    border-bottom: none;
    vertical-align: top;
    z-index: 2;
    visibility: visible;
    left: 0;
    top: 0;
    position: absolute;
  }

  #mainbody
  {
    left: 0;
    top: 0;
    margin: 0;
    position: absolute;
    padding: 10px;
    overflow: auto;
    height: 100%;
    z-index: 1;
    background-repeat: no-repeat;
    background-position: bottom right;
    background-attachment: fixed;
  }
</style>

<style type="text/css" media="print">
  #nsr
  {
    visibility: none;
  }

  #mainbody
  {
    overflow: visible;
  }
</style>
<script type="text/javascript" language="JavaScript" src="nonscroll.js"></script>

</head>
<body scroll="no">

<div id="page">



        <div id="content">
          <div id="content-inner">
          



  
          <div id="nsr">
            <table border="0" cellspacing="0" cellpadding="4" width="100%">
              <tr valign="top">
                <td align="left">
  


                  <p class="p_Heading1"><span class="f_Heading1">Set Up Unit Testing</span></p>



  
                </td>
                <td align="right">
                  <a href="introduction.htm" onmouseover="document.images.main.src='button_main_h.gif'" onmouseout="document.images.main.src='button_main.gif'">
                    <img name="main" src="button_main.gif" border=0 alt="Return to Introduction">
                  </a>&nbsp;
    
                  <a href="xunit_testing.htm" onmouseover="document.images.prev.src='button_prev_h.gif'" onmouseout="document.images.prev.src='button_prev.gif'">
                    <img name=prev src="button_prev.gif" border=0 alt="Previous page" />
                  </a>&nbsp;
    
    
    
                  <a href="running_unit_tests.htm" onmouseover="document.images.next.src='button_next_h.gif'" onmouseout="document.images.next.src='button_next.gif'">
                    <img name=next src="button_next.gif" border=0 alt="Next page" />
                  </a>
    
    
                </td>
              </tr>
            </table>
          </div>
          <div id="mainbody">
  


                <p class="p_BodyText"><span class="f_BodyText">In order to use unit testing in Enterprise Architect, you must first set it up. This happens in two parts. </span></p>
<p class="p_BodyText"><span class="f_BodyText">Firstly the appropriate <a href="creatinganewscript_3.htm">tests must be defined</a>. Enterprise Architect is able to help with this. By using the <a href="junit_transformation.htm">JUnit </a> or <a href="nunit_transformation.htm">NUnit</a> transformations and <a href="generatesourcecode.htm">code generation</a> you can create test method stubs for all of the public methods in each of your Classes.</span></p>
<p class="p_BodyText"><span class="f_BodyText">The following is an </span><span class="f_BodyText" style="font-style: italic;">NUnit</span><span class="f_BodyText"> example in </span><span class="f_BodyText" style="font-style: italic;">C#</span><span class="f_BodyText"> that is followed through the rest of this topic, although it could also be any other .Net language or Java and JUnit.</span></p>
<p class="p_Code"><span class="f_Code">[TestFixture]</span></p>
<p class="p_Code"><span class="f_Code">public class CalculatorTest</span></p>
<p class="p_Code"><span class="f_Code">{</span></p>
<p class="p_Code"><span class="f_Code">&nbsp;</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">[Test]</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">public void testAdd(){</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">Assert.AreEqual(1+1,2);</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">}</span></p>
<p class="p_Code"><span class="f_Code">&nbsp;</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">[Test]</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">public void testDivide(){</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">Assert.AreEqual(2/2,1);</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">}</span></p>
<p class="p_Code"><span class="f_Code">&nbsp;</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">[Test]</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">public void testMultiply(){</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">Assert.AreEqual(1*1,1);</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">}</span></p>
<p class="p_Code"><span class="f_Code">&nbsp;</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">[Test]</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">public void testSubtract(){</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">Assert.AreEqual(1-1,1);</span></p>
<p class="p_Code"> &nbsp; &nbsp; &nbsp; &nbsp;<span class="f_Code">}</span></p>
<p class="p_Code"><span class="f_Code">}</span></p>
<p class="p_BodyText"><span class="f_BodyText">This code can be reverse engineered into Enterprise Architect so that Enterprise Architect can record all test results against this Class.</span></p>
<p class="p_BodyText"><span class="f_BodyText">Once the unit tests are set up, you can then set up the Build and Test scripts to run the tests. These scripts must be set up against a package.</span></p>
<p class="p_BodyText"><span class="f_BodyText">The sample above can be called by setting up the </span><span class="f_UIControl"><a href="build_scripts.htm">Package Build Scripts</a></span><span class="f_BodyText"> dialog as follows.</span></p>
<p class="p_TextIndentedL2"><img src="testscript_nunit2.png" width="641" height="330" border="0" alt="testScript_nunit2"></p>
<p class="p_BodyText"><span class="f_BodyText">If Enterprise Architect is to handle unit testing, it is important that you select the </span><span class="f_MenuKeyField">Capture Output</span><span class="f_BodyText"> checkbox and select the appropriate </span><span class="f_MenuKeyField">Output Parser</span><span class="f_BodyText"> for the testing. Without doing this you won't see the program output and therefore you cannot open the source at the appropriate location.</span></p>




            </div>
          </div>
        </div>



</div>


</body>
</html>
